<template>
	<view v-if="pageShow" class="mainpadding2">
		<view class="mainpadding_top radius" style="background-color: #fbf6f1;">
			<view class="flexleft ">
				<view class="margin_right2" style="min-width: 120rpx;" v-if="dataAll.data_type==1">
					<view class="huang_text titletext bold">${{dataAll.dk_money}}</view>
					<view class="hui_text main_size margin_top bold">滿{{dataAll.di_money}}可用</view>
				</view>
				<view class="margin_right2" v-if="dataAll.data_type==2">
					<image :src="dataAll.image_text" mode="" style="width: 120rpx;height: 120rpx;min-width: 120rpx;"></image>
					<view class="hui_text main_size margin_top bold">滿{{dataAll.di_money}}可用</view>
				</view>
				<view class="line margin_right2"></view>
				<view class="hei_text titletext bold">{{dataAll.name}}</view>
			</view>
			<view class="margin_top hui_text bold">使用時間<text class="hong_text">{{http.timereturn(dataAll.starttime*1000)}}~{{http.timereturn(dataAll.endtime*1000)}}</text></view>
			<view class="flexright margin_top hei_text main_size bold">共：{{dataAll.num}}張 餘：{{dataAll.end_num}}張</view>
		</view>
		<view class="posibottom mainpadding">
			<view class="submitbtn" @click="submit">領取優惠券</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listid:6,
				pageShow:false,
				dataAll:{},
				paraString:"",
			}
		},
		onLoad(options) {
			this.paraString = window.location.href //还可以  window.location.search.substring()
			let time = this.getQueryVariable('time') //code是url後面带的
			this.listid = this.getQueryVariable('id') //code是url後面带的
			console.log(this.paraString,"原来鏈接",time,"時間",this.listid,"優惠券id");
			let codetime = (Number(new Date())- Number(time))  > 60*1000?true:false//是否大於10s如果大於10s了就提示過期
			console.log(codetime,"99999",Number(new Date()) - Number(time),"7788");
			if(codetime){
				this.http.toast("二維碼已過期")
				setTimeout(()=>{
					uni.switchTab({
						url:"/pages/index/index"
					})
				},1000)
			}else{
				this.init()
			}
		},
		methods: {
			getQueryVariable(variable) {
				var query = this.paraString;
				var rooms = query.split('?');
				for (var i = 0; i < rooms.length; i++) {
					var pair = rooms[i].split('=');
					if (pair[0] == variable) {
						return (pair[1].split('&'))[0]
					}
				}
				//或者拼接&後面的值
				var vars = query.split('&')
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split('=')
					if (pair[0] == variable) {
						return pair[1]
					}
				}
			},
			init(){
				uni.showLoading({
					mask:true,
					title:"請稍後"
				})
				this.http.request("/api/shop/shop_ralldeail", 'POST', {
					id: this.listid
				}).then(res=>{
					uni.hideLoading()
					if(res.code==1){
						this.dataAll = res.data
						this.pageShow = true
					}else{
						this.http.toast(res.msg)
						setTimeout(()=>{
							uni.reLaunch({
								url:"/pages/index/index"
							})
						},1000)
					}
				}).catch(err=>{
					uni.hideLoading()
					this.http.toast(res.msg)
				})
			},
			submit(){
				this.http.request("/api/shop/addshop_rall", 'POST', {
					id: this.listid
				}).then(res=>{
					this.http.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.switchTab({
								url:"/pages/index/index"
							})
						},1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.line {
		width: 2rpx;
		height: 50rpx;
		background-color: #999;
	}
</style>
